<ul class="dropdown-menu">
  <% favs = current_user.org_favorites.order(:ci_name) %>
  <% if favs.present? %>
    <% fav_groups = favs.group_by { |f| f.ci_class_name.split('.').last } %>
    <% fav_groups.each do |ci_class, group| %>
      <li class="dropdown-submenu">
        <a class="dropdown-toggle" data-toggle="dropdown">
          <% ci_class_name = group.first.ci_class_name
             icon_name = site_icon!(ci_class_name.split('.').last.downcase) %>
          <%= icon_name.blank? ? image_tag(ci_class_image_url(ci_class_name), :class => 'icon') : icon(icon_name, nil, 'icon') %>
          <%= ci_class %>
        </a>
        <ul class="dropdown-menu">
          <% group.each do |favorite| %>
            <li>
              <%= link_to(favorite_path(favorite.ci_id), :method => :get) do %>
                <%= favorite.ci_name %><br>
                <small style="margin-left:10px"><%= favorite.ns_path %></small>
              <% end %>
            </li>
          <% end %>
        </ul>
      </li>
    <% end %>
    <li class="divider"></li>
  <% else %>
    <li><%= link_to_function('No favorites stored', '') %></li>
  <% end %>
  <li><%= link_to(content_tag(:small, 'Manage favorites...'), account_profile_path(:anchor => 'favorites')) %></li>
</ul>
